home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 9 / Amoszine 9 (Disk 3 of 3).adf / RWilliams_Stuff.lha / momentumball.amos / momentumball.amosSourceCode < prev    next >
Encoding:
AMOS Source Code  |  1995-09-14  |  5.1 KB  |  259 lines

  1. '
  2. ' MOMENTUMBALL 
  3. '
  4. ' (c) Richard Williams 
  5. '  
  6. ' Revision Date : 14/9/95  
  7. '
  8. ' Demonstration of momentum and hardware scrolling 
  9. '
  10. ' The game itself is simple and a little fun ! 
  11. ' All you have to do is move the ball (blue) across the screen and 
  12. ' hit the opposite wall (on the right) and come back and hit 
  13. ' the wall you started at !  Got it ?  Oh by the way, avoid  
  14. ' the computer (red) ball. 
  15. '  
  16. ' Initialise Screen (open big bitmap)
  17. Screen Open 0,1000,200,4,Lowres
  18. Screen Display 0,128,50,,
  19. Paper 0 : Pen 1 : Flash Off : Curs Off : Hide : Cls 
  20. Palette 0,$FFF,$F00,$F
  21. Cls 
  22. ' Generate and grab sprites from screen
  23. Screen Hide 
  24. Ink 1
  25. Circle 100,100,8
  26. Ink 3
  27. Paint 100,100,1
  28. Get Bob 1,92,92 To 109,109
  29. Cls 
  30. Ink 1
  31. Circle 100,100,8
  32. Ink 2
  33. Paint 100,100,1
  34. Get Bob 2,92,92 To 109,109
  35. Cls 
  36. Screen Show 
  37. ' Initialise game time variables 
  38. Dim LAG(15),LSL(15)
  39. Restore LEVEL_DATA
  40. For N=1 To 15
  41.    Read LAG(N),LSL(N)
  42. Next 
  43. L=0
  44. SC=0
  45. DEAD=False
  46. Set Line %1010101010101010
  47. ' Main game loop 
  48. Repeat 
  49.    Cls 
  50.    Colour 0,0
  51.    Pen 1
  52.    Inc L
  53.    Print "LEVEL ";L
  54.    Wait 100
  55.    Ink 3
  56.    Cls 
  57.    For N=0 To 964 Step 16
  58.       Draw N,0 To N,200
  59.    Next 
  60.    For N=0 To 200 Step 16
  61.       Draw 0,N To 960,N
  62.    Next 
  63.    Ink 2
  64.    Box 0,0 To 960,199
  65.    Box 1,1 To 959,198
  66.    ' Initialise level time variables
  67.    A=0 : B=0 : C=50 : D=50 : DD=0 : CC=0
  68.    E=Rnd(500)+400 : F=Rnd(100)+50 : EE=0 : FF=0
  69.    AG=LAG(L) : SL=LSL(L)
  70.    HIT_FAR_SIDE=False
  71.    T=1000
  72.    CREG0=0
  73.    LEVEL_FINISHED=False
  74.    Repeat 
  75.       ' Control timer and screen getting brighter bit
  76.       T=T-1
  77.       If T<0
  78.          If T mod 8=0
  79.             Add CREG0,$111
  80.             If CREG0=$FFF
  81.                DEAD=True
  82.             End If 
  83.             Colour 0,CREG0
  84.          End If 
  85.       End If 
  86.       ' Set the screen offset (hardware scroll)
  87.       Screen Offset 0,A,B
  88.       '
  89.       ' Players Bob Control  
  90.       '
  91.       ' Interpret users controls 
  92.       J=Joy(1)
  93.       ' Add to momentum value
  94.       If J and 1
  95.          DD=DD-1
  96.       End If 
  97.       If J and 2
  98.          DD=DD+1
  99.       End If 
  100.       If J and 4
  101.          CC=CC-1
  102.       End If 
  103.       If J and 8
  104.          CC=CC+1
  105.       End If 
  106.       ' Check momentum does not exceed a certain value 
  107.       ' ie this is your maximum speed in pixels
  108.       If DD>4
  109.          DD=4
  110.       End If 
  111.       If DD<-4
  112.          DD=-4
  113.       End If 
  114.       If CC>4
  115.          CC=4
  116.       End If 
  117.       If CC<-4
  118.          CC=-4
  119.       End If 
  120.       ' Move players sprite - Add the balls momentum values
  121.       C=C+CC
  122.       D=D+DD
  123.       ' Only scroll if balls x coordinate is inside these limits 
  124.       If(C>159) or(C<806)
  125.          A=A+CC
  126.       End If 
  127.       ' Check if far side is hit - Reverese momentum makes ball bounce 
  128.       If(C>940)
  129.          CC=-4
  130.          If Not(HIT_FAR_SIDE)
  131.             Bell 
  132.             HIT_FAR_SIDE=True
  133.          End If 
  134.       End If 
  135.       ' Check if player has reached home again (if not - just bounce)
  136.       If(C<0)
  137.          CC=4
  138.          ' Check for end of level 
  139.          If HIT_FAR_SIDE
  140.             For N=1 To 90 Step 4
  141.                Bell N
  142.                Wait 1
  143.             Next 
  144.             SC=SC+(T*3)
  145.             LEVEL_FINISHED=True
  146.          End If 
  147.       End If 
  148.       ' Set screen offset when ball is outside scrolling range 
  149.       If C<160
  150.          A=0
  151.       End If 
  152.       If C>805
  153.          A=650
  154.       End If 
  155.       ' Control y direction bounce 
  156.       If(D<0)
  157.          DD=4
  158.       End If 
  159.       If(D>182)
  160.          DD=-4
  161.       End If 
  162.       Bob 1,C,D,1
  163.       '
  164.       ' Computer Bob Control 
  165.       '
  166.       ' Control momentum dependent on players ball position
  167.       If C<E
  168.          Dec EE
  169.       End If 
  170.       If C>E
  171.          Inc EE
  172.       End If 
  173.       If D>F
  174.          Inc FF
  175.       End If 
  176.       If D<F
  177.          Dec FF
  178.       End If 
  179.       ' Check for balls maximum momentum value 
  180.       If EE>AG
  181.          EE=AG
  182.       End If 
  183.       If EE<-AG
  184.          EE=-AG
  185.       End If 
  186.       If FF>AG
  187.          FF=AG
  188.       End If 
  189.       If FF<-AG
  190.          FF=-AG
  191.       End If 
  192.       ' Add momentum to computer ball (SL=slow down effect)
  193.       E=E+(EE/SL)
  194.       F=F+(FF/SL)
  195.       ' If ball hits wall - bounce 
  196.       If E<0 or E>964
  197.          EE=-EE
  198.       End If 
  199.       If F<0 or F>182
  200.          FF=-FF
  201.       End If 
  202.       Bob 2,E,F,2
  203.       Wait Vbl 
  204.       ' Detect player/computer collision 
  205.       If Bob Col(1)=-1
  206.          DEAD=True
  207.       End If 
  208.    Until LEVEL_FINISHED or DEAD
  209.    If LEVEL_FINISHED and L=15
  210.       DEAD=True
  211.    End If 
  212. Until DEAD
  213. ' Reset screen 
  214. Screen Offset 0,0,0
  215. Colour 0,0
  216. Cls 
  217. Boom 
  218. Restore MESSAGES
  219. For N=1 To L
  220.    Read A$
  221. Next 
  222. Print A$
  223. Print "Score=";SC
  224. If L=15
  225.    Print "You have defeated this game !"
  226. End If 
  227. End 
  228. LEVEL_DATA:
  229. Data 12,6
  230. Data 18,6
  231. Data 24,6
  232. Data 30,6
  233. Data 36,6
  234. Data 15,5
  235. Data 20,5
  236. Data 25,5
  237. Data 30,5
  238. Data 16,4
  239. Data 20,4
  240. Data 24,4
  241. Data 12,3
  242. Data 18,3
  243. Data 16,2
  244. MESSAGES:
  245. Data "Oh dear, get a life..."
  246. Data "A feeble effort..."
  247. Data "Pretty rubbish..."
  248. Data "Hmmm, more practice, a lot more..."
  249. Data "Well, getting there..."
  250. Data "Reasonable..."
  251. Data "Ok, not bad..."
  252. Data "Smart Arse..."
  253. Data "Steady on..."
  254. Data "Wow, not bad..."
  255. Data "WHAT! pretty damn good..."
  256. Data "Thats a hard act to follow, git..."
  257. Data "You are my mentor..."
  258. Data "You are a demi-god..."
  259. Data "You are the UNIVERSE!"